﻿using System;
using System.Collections.Generic;
using System.Data;

using System.Text;
using Module.Common.Models;
using Module.Core.DAO;
using Module.Core.EntitiesInfo.TablesInfo;
using Module.Core.DAO.DAO;


namespace Module.Core.BusinessLogic.Products
{
   public class ProductsBL
    {
       
       /// <summary>
        /// Saves a record to the Product table.
		/// </summary>
		public static int Insert(ProductsInfo productsInfo)
		{
			try
			{
				return new ProductsDao().Insert(productsInfo);
			}
			catch (Exception ex)
			{
				throw;
			}

		}
     
		/// <summary>
		/// Saves a record to the Product table.
		/// </summary>
        public static void Update(ProductsInfo productsInfo)
		{
			try
			{
				new ProductsDao().Update(productsInfo);
			}
			catch (Exception ex)
			{
				throw;
			}

		}

        public static void UpdateStatus(int producsId, int status)
        {
            try
            {
                new ProductsDao().UpdateStatus(producsId, status);
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        public static void UpdateAllProducts(int producsId, int type, int param)
        {
            try
            {
                new ProductsDao().UpdateAllProducts(producsId, type, param);
            }
            catch (Exception ex)
            {
                throw;
            }

        }

		/// <summary>
		/// Delete a record from the Products table.
		/// </summary>
        public static void Delete(int productsId)
		{
			try
			{
				new ProductsDao().Delete(productsId);
			}
			catch (Exception ex)
			{
				throw;
			}

		}

		// <summary>
		// Selects a single record from the Products table.
		// </summary>
        public static ProductsInfo Select(int productsId)
        {
            try
            {
                return new ProductsDao().Select(productsId);
            }
            catch (Exception ex)
            {
                throw;
            }

        }
        public static ProductsInfo SelectFollowKeywors(string  keywors, int status)
        {
            try
            {
                return new ProductsDao().SelectFollowKeywors(keywors, status);
            }
            catch (Exception ex)
            {
                throw;
            }

        }
       //sản phẩm cùng loại

        public static DataTable Products_SelectSameType(int status, int zoneId,int topN,int type)
        {
            try
            {
                return new ProductsDao().Products_SelectSameType(status, zoneId,topN,type);
            }
            catch (Exception ex)
            {
                throw;
            }

        }
       

        public static ProductsInfo SelectProductCategory(int zoneId, int status)
        {
            try
            {
                return new ProductsDao().SelectProductCategory(zoneId, status);

            }
            catch (Exception ex)
            {
                throw;
            }

        }
        public static ProductsInfo SelectCity(int cityId)
        {
            try
            {
                return new ProductsDao().SelectCity(cityId);
            }
            catch (Exception ex)
            {
                throw;
            }

        }
		// <summary>
		// Selects all records from the Singer table.
		// </summary>
        public static CHRTList<ProductsInfo> SelectAll(int status)
        {
            try
            {
                return new ProductsDao().SelectAll(status);
            }
            catch (Exception ex)
            {
                throw;
            }

        }
        public static CHRTList<ProductsInfo> SearchAll(string keyword, int status, int from, int to, int checkType, int zoneId, DateTime createdOnFrom, DateTime createdOnTo)
        {
            try
            {
                return new ProductsDao().SearchAll(keyword, status, from, to, checkType, zoneId, createdOnFrom,createdOnTo);
            }
            catch (Exception ex)
            {
                throw;
            }

        }  
        public static int GetCount(string keyword, int status,int zoneId)
        {
            try
            {
                return new ProductsDao().GetCount(keyword, status, zoneId);
            }
            catch (Exception)
            {

                throw;
            }
        }

        public static DataTable Search(int status, string productName, int zoneId, DateTime starDatetime, DateTime endDatetime, int beginRow, int endRow, string orderByColumn)
        {
            try
            {
                return new ProductsDao().Search(status, productName, zoneId, starDatetime, endDatetime, beginRow, endRow, orderByColumn);
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        public static int SelectCount(int status, string productName, int zoneId, DateTime starDatetime, DateTime endDatetime)
        {
            try
            {
                return new ProductsDao().SelectCount(status, productName, zoneId, starDatetime, endDatetime);
            }
            catch (Exception ex)
            {
                throw;
            }

        }
        // <summary>
        // Selects a single record from the Products table.
        // </summary>
        public static DataTable SelectIndex(int status)
        {
            try
            {
                return new ProductsDao().SelectIndex(status);
            }
            catch (Exception ex)
            {
                throw;
            }

        }

       /// <summary>
       /// Get danh sách sản phẩm
       /// </summary>
       /// <param name="topN">Số bản ghi cần lấy</param>
       /// <param name="zoneId">Chuyên mục</param>
       /// <param name="status">Status =1 hiển thị</param>
        /// <param name="checkType">checkType=1 sản phẩm nổi bật; 2 sản phẩm hot; 4 sản phẩm mới nhất; 8 sản phẩm giảm giá</param>
       /// <returns></returns>
        public static DataTable GetDataLatest(int topN, int zoneId, int status, int checkType)
        {
            try
            {
                return new ProductsDao().GetDataLatest( topN,  zoneId,  status,  checkType);
            }
            catch (Exception ex)
            {
                throw;
            }

        }
        public static DataTable GetProductsList12(int beginNumber, int endNumber, int isTotal)
        {
            return new ProductsDao().Get12Row(beginNumber, endNumber, isTotal);
        }

        public static DataTable GetTop3(int status)
        {
            return new ProductsDao().GetTop3(status);
        }

        public static DataTable GetSanPhamCungNhom(int status)
        {
            return new ProductsDao().GetSanPhamCungNhom(status);
        }

        public static DataTable GetCategory(int lang, int checkZone, int parentID, int moduleMenu, string keyOrderby)
        {
            return new ProductsDao().GetCategory( lang,  checkZone,  parentID,  moduleMenu,  keyOrderby);
        }

        public static int SelectCount(bool isTotalRow)
        {
            try
            {
                return new ProductsDao().SelectCount(isTotalRow);
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        public static int GetPageviews(string keyword, int status)
        {
            try
            {
                return new ProductsDao().GetPageview(keyword, status);
            }
            catch (Exception)
            {

                throw;
            }
        }

        public static DataSet GetProduct(int status, int currPage, int recodperPage, int pageSize)
        {
            try
            {
                DataSet ds = new DataSet();

                ds = new ProductsDao().GetProduct(status, currPage, recodperPage, pageSize);
                if (ds != null)
                    return ds;
                return null;
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        public static DataSet GetProductDanhMuc(int currPage, int recodperPage, int pageSize, string zoneUrl)
        {
            try
            {
                DataSet ds = new DataSet();

                ds = new ProductsDao().GetProductDanhMuc( currPage, recodperPage, pageSize,zoneUrl);
                if (ds != null)
                    return ds;
                return null;
            }
            catch (Exception ex)
            {
                throw;
            }

        }
       //hiện thị danh sách sản phẩm theo từng chuyên mục
        public static DataTable GetProductChiTietDanhMuc(int zoneId,int status)
        {
            return new ProductsDao().GetProductChiTietDanhMuc(zoneId,status);
        }
       

    }
    }

